<style src="./index.scss" lang="scss" scoped rel="stylesheet/scss"></style>
<template src="./index.html"></template>
<script>
    export default {
        mixins: [Vue.prototype.$vFN.Mixins.Base, Vue.prototype.$vFN.Mixins.Edit],
        props: {
// 使用者window实例 必定义
            appWindow: {
                type: Object,
                default: null,
            },
        },
        computed: {
            
        },

        data() {
            return {
                // 初始化状态
                initLoad: false,
                // 编辑类型
                editType: "",
                // 商品分组
                groupsOptions: [],
                form: {
                    // 商品分组
                    groupsIdLst: [],

                }
            };
        },

        methods: {
           
            validate(e) {
                return this.mixinEdit_formValidate("editForm")
            },

            getData() {

                let _groupsIdLst = []
                if (this.form.groupsIdLst.length > 0) {
                    this.form.groupsIdLst.forEach(item => {
                        _groupsIdLst.push({
                            groupsId: item[1],
                            parentGroupsId: item[0],
                        })
                    })
                }
                let _d = {
                    groupsIdLst: _groupsIdLst,

                }

                return _d;
            },
            async install(params_) {
                this.editType = params_.type;

                // 数据源 分组
                this.groupsOptions = await this.$vFN.Tools.getSelectListSource({
                    domain: "APP_MAIN_DOMAIN",
                    url: "mall-site-portal/product/listGroups",
                },this.appWindow);
                

                if (params_.datasource) {
                    let _groupsLst = params_.datasource.groupsLst

                    this.form.groupsIdLst = _groupsLst.map(item => {
                        return [item.parentGroupsId, item.groupsId]
                    });
                }
                this.initLoad = true;
                this.returnData();
            },
            async uninstall() {
                this.$refs["editForm"].resetFields();
            },
            returnData() {
                this.$emit('change', {
                    data: this.getData(),
                    load: this.initLoad
                })
            },
        },
        mounted() {},
        beforeCreate() {},
        watch: {
            "form": {
                handler(newName, oldName) {
                    this.returnData();
                },
                immediate: true,
                deep: true,
            }
        },
    };
</script>